﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Configuration;

using IFServerDLL;
using System.ServiceModel;
using IFServerDLL.Model;
using IFServerDLL.Broker;
using System.Linq;
using HCY.CTP.DBShangZheng;

namespace IFDemoServer
{
    
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class CommandData : ICommandData
    {
        static Dictionary<Guid, UserInDemoService> _DictUser = new Dictionary<Guid, UserInDemoService>();






        public UserOrderTrade Login(BrokerUserBase brokerUser)
        {
            //lock (_DictUser)
            {
                if(_DictUser.ContainsKey(brokerUser.UserID )==false)
                {
                    _DictUser.Add(brokerUser.UserID, new UserInDemoService(brokerUser));
                }
                
                return _DictUser[brokerUser.UserID].UserOrderTrade;
            }
        }


        public void OrderInsert(Guid userID, UserOrdBase ord)
        {
            if (_DictUser.ContainsKey(userID) == false)
            {
                //donothing
            }
            else
            {
                _DictUser[userID].OrderInsert(ord);
            }
        }

        public void OrderCancel(Guid userID, Guid orderID,Guid calcID)
        {
            if (_DictUser.ContainsKey(userID) == false)
            {
                //donothing
            }
            else
            {
                _DictUser[userID].OrderCancel(orderID,calcID);
            }
        }

        
       


        public void AddMarketData(Guid userID, IFServerDLL.DB.MyDBData data)
        {
            if (_DictUser.ContainsKey(userID) == false)
            {
                //donothing
            }
            else
            {
                _DictUser[userID].AddMarketData( data);
            }
        }
    }
}
